﻿using DotNet.HowToUseInterfacesDemo.GoodUse.Config;
using DotNet.HowToUseInterfacesDemo.GoodUse.Services;

namespace DotNet.HowToUseInterfacesDemo.GoodUse
{
    class ProperUseOfInterfaces
    {
        /**********************************************************************
        **  Here you'll see how I feel interface can be used properly with 
        **  dependency injection. This is a pretty simple app to send messages
        **  to people via their prefered communication method. Obviously this
        **  is overly simplified. 
        **  
        **  You'll notice that no class depends on an implimentation only the 
        **  abstraction. This allows us to follow the dependency inversion 
        **  principle of SOLID. 
        **  
        **  You'll also notice that by using interfaces you can and should 
        **  limit what methods are available. You usually don't want every 
        **  method in the class availble in the interface. This is will be 
        **  better explained in the DesignPatterns.ComponentPatternDemo. This
        **  allows us to follow the Interface Segregation principle of SOLID.
        **  Many of the interfaces I write have only one or two methods.
        **
        **  Say we've been tasked with adding another communication method, now 
        **  we only have to create a new class to handle it and register it 
        **  with dependency injection. I don't have to touch any other classes. 
        **  This allows us to follow the Open for Extension/Closed for 
        **  Modification Principle of SOLID.
        **
        **********************************************************************/

        public static void StartHere()
        {
            //Setup dependency injection
            var serviceLocator = new ObjectFactory(new DependencyInjectionConfig());

            //Get an instance
            var messengerService = serviceLocator.Get<IMessengerService>();
            messengerService.SendMessage("Hello, I need help!");
        }
    }
}
